package com.suep.system.mapper;

import com.suep.system.domain.Menu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MenuMapper {
    @Select("select * from `menu` where `id` in (select `menu_id` from role_menu where role_id=#{roleId}) ")
    public List<Menu> selectMenuByRoleId(Long id);

    //    查询所有菜单

    @Select("select * from `menu`")
    List<Menu> selectAllMenus();

    @Insert("insert into `menu` (id,name,description,parent_id,create_time,icon,order)" +
            "values (#{id},#{name},#{description},#{parentId},#{create_time},#{icon},#{order})")
    Integer insertMenu(Menu menu);

    @Update("update `menu` set `name`=#{name}, `description`=#{description}, `parent_id`=#{parentId}, " +
            "`create_time`=#{createTime}, `icon`=#{icon}, `order`=#{order} where `id`=#{id}")
    Integer updateMenu(Menu menu);

    @Delete("delete from `menu` where `id` = #{id} ")
    Integer deleteMenuById(Long id);

    //与菜单删除组成业务，实现级联删除
    @Delete("DELETE FROM rolemenu WHERE menu_id in #{menuId}")
    void deleteRoleMenuByMenuId(Long menuId);

    @Select("select * from `menu` where `name` like CONCAT('%', #{name}, '%')")
    List<Menu> selectMenusByName(String name);

    //    分页查询
    @Select("select * from `menu` limit #{offset}, #{limit}")
    List<Menu> selectMenusByPage(@Param("offset") Integer offset, @Param("limit") Integer limit);


}
